package com.xudow.app.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.xudow.app.R;
import com.xudow.app.XApplication;
import com.xudow.app.ui.widget.TitleBarTextView;

/**
 * 课程中心 (@Delete)
 *优选课程/课兜（我发布的课程）
 * @author lukecheng
 */
public class CourseListActivity extends BaseActivity {

    private CourseListFragment courseListFragment;
    private TitleBarTextView title;
    private String mode;

    private LocationClient mLocationClient;
    private NotifyLocationListener listener;
    private double longtitude, latitude;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_course_list);

        listener = new NotifyLocationListener();
        mLocationClient = new LocationClient(this);
        mLocationClient.registerLocationListener(listener);
        mLocationClient.start();
        title=(TitleBarTextView)findViewById(R.id.titlebar);
        courseListFragment = (CourseListFragment)
                getSupportFragmentManager().findFragmentById(R.id.course_fragment);

        Intent intent = getIntent();
        mode = intent.getStringExtra("mode");

        if("recommend".equals(mode)){
            title.setText("优选课程");
            findViewById(R.id.search_iv).setVisibility(View.INVISIBLE);
            courseListFragment.loadRecommendlist();
        }else if ("mycourselist".equals(mode)){
            title.setText("我的课兜");
            findViewById(R.id.search_iv).setVisibility(View.INVISIBLE);
            courseListFragment.LoadMyCourselist();
        }
    }

    public void onBackBtnClick(View view) {
        finish();
    }

    /**
     * 搜索icon点击事件
     *
     * @param view
     */
    public void onSearchClick(View view) {

        Intent intent = new Intent(this, CourseSearchActivity.class);
        startActivity(intent);
    }

    @Override
    protected void onStop() {
        super.onStop();

        mLocationClient = null;
        listener = null;
    }

    public class NotifyLocationListener implements BDLocationListener {
        @Override
        public void onReceiveLocation(BDLocation location) {
            //Receive Location
            longtitude = location.getLongitude();
            latitude = location.getLatitude();

            XApplication application = (XApplication) getApplication();
            application.latitude = latitude;
            application.longitude = longtitude;

            courseListFragment.refreshLngLat();
        }
    }


}


